#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

// 3443. K 次修改后的最大曼哈顿距离
// https://leetcode.cn/problems/maximum-manhattan-distance-after-k-changes/description/?envType=daily-question&envId=2025-06-20

class Solution {
public:
    int maxDistance(string s, int k) {
        unordered_map<char, int> recordCntOfChar;
        int ans = 0;
        for (int i = 0; i < s.size(); i++)
        {
            char curCh = s[i];
            recordCntOfChar[curCh]++;
            auto f = [&](int x, int y)->int
            {
                int sub = min(x,min(y,k));
                k -= sub;
                return abs(x - y) + sub * 2;
            };
            ans = max(ans, f(recordCntOfChar['E'], recordCntOfChar['W']) + f(recordCntOfChar['S'], recordCntOfChar['N']));
        }
        return ans;
    }
};

int main()
{
    return 0;
}